<template>
  <div>
    <div class="swipe_container">
      <el-carousel :interval="3000" arrow="always">
        <el-carousel-item v-for="item in carousels" :key="item.carousel_id">
          <img :src="'http://47.115.85.237:3000/' + item.imgPath" alt="" />
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="commodity_container w">
      <div class="left_box_container">
        <img src="../assets/imgs/xiaomi.png" alt="" />
      </div>
      <div class="right_box_container">
        <div class="top_container">
          <div
            class="mobile_container"
            v-for="(item,index) in hotList"
            :key="index"
            v-show="index < 4"
          >
            <img
              :src="'http://47.115.85.237:3000/' + item.product_picture"
              alt=""
            />
            <p>{{ item.product_name }}</p>
            <p>{{ item.product_title }}</p>
            <p>
              <b>￥{{ item.product_price }}</b>
              <s>￥{{ item.product_selling_price }}</s>
            </p>
          </div>
        </div>
        <div class="bottom_container">
          <div
            class="mobile_container"
            v-for="(item,index) in hotList"
            :key="index"
            v-show="index > 3"
          >
            <img
              :src="'http://47.115.85.237:3000/' + item.product_picture"
              alt=""
            />
            <p>{{ item.product_name }}</p>
            <p>{{ item.product_title }}</p>
            <p>
              <b>￥{{ item.product_price }}</b>
              <s>￥{{ item.product_selling_price }}</s>
            </p>
          </div>
          <div class="mobile_container2">
            <h3>浏览更多>></h3>
          </div>
        </div>
      </div>
    </div>

    <div class="commodity_container w">
      <div class="left_box_container">
        <img src="../assets/imgs/jd.png" alt="" />
      </div>
      <div class="right_box_container">
        <div class="top_container">
          <div
            class="mobile_container"
            v-for="(item,index) in showList"
            :key="index"
            v-show="index < 4"
          >
            <img
              :src="'http://47.115.85.237:3000/' + item.product_picture"
              alt=""
            />
            <p>{{ item.product_name }}</p>
            <p>{{ item.product_title }}</p>
            <p>
              <b>￥{{ item.product_price }}</b>
              <s>￥{{ item.product_selling_price }}</s>
            </p>
          </div>
        </div>
        <div class="bottom_container">
          <div
            class="mobile_container"
            v-for="(item,index) in showList"
            :key="index"
            v-show="index > 3"
          >
            <img
              :src="'http://47.115.85.237:3000/' + item.product_picture"
              alt=""
            />
            <p>{{ item.product_name }}</p>
            <p>{{ item.product_title }}</p>
            <p>
              <b>￥{{ item.product_selling_price }}</b>
              <s> ￥{{ item.product_price }} </s>
            </p>
          </div>
          <div class="mobile_container2">
            <h3>浏览更多>></h3>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getCarousel, getHot, getGoods } from "../api/home";
export default {
  data() {
    return {
      carousels: [],
      hotList: [],
      showList: [],
    };
  },
  created() {
    // 请求轮播图数据
    getCarousel().then((res) => {
      console.log(res);
      this.carousels = res.carousel;
    });

    // 请求热门商品数据
    getHot().then((res) => {
      this.hotList = res.Product;
      console.log(res);
    });
    // 各类商品数据
    getGoods().then((res) => {
      console.log(res);
      this.showList = res.Product;
    });
  },
};
</script>
<style lang="scss">
* {
  margin: 0;
  padding: 0;
}
.w {
  width: 1200px;
  margin: 0 auto;
}
.el-carousel__item h3 {
  color: #475669;
  font-size: 18px;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
.swipe_container {
  width: 100%;
  height: 500px;
  // background-color: red;
  img {
    width: 100%;
    height: 100%;
    z-index: 666;
  }
}
.el-carousel__container {
  height: 500px !important;
}
.commodity_container {
  height: 600px;
  // background-color: skyblue;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  margin-top: 20px;
}
.left_box_container {
  width: 20%;
  height: 100%;
  // background-color: red;
  img {
    width: 100%;
    height: 100%;
  }
}
.right_box_container {
  width: 80%;
  height: 100%;
  background-color: #f4f4f4;
  display: inline-flex;
  justify-content: space-around;
  flex-wrap: wrap;
}
.top_container {
  width: 100%;
  height: 50%;
  display: inline-flex;
  justify-content: space-around;
  // background-color: red;
  .mobile_container {
    width: 24%;
    height: 99%;
    background-color: #fff;
  }
  .mobile_container:hover {
    transform: scale(1.05);
    transition: all 1s;
    background-color: #fff;
  }
  img {
    width: 100%;
    height: 80%;
  }
  p {
    font-size: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 5px 0px;
    b {
      font-size: 13px;
      font-weight: 700;
      color: red;
    }
  }
}
.bottom_container {
  display: inline-flex;
  justify-content: flex-start;
  width: 100%;
  height: 50%;
  .mobile_container {
    width: 24%;
    height: 99%;
    background-color: #fff;
    margin: 0 5px;
  }
  .mobile_container:hover {
    transform: scale(1.05);
    transition: all 1s;
    background-color: #fff;
  }
  img {
    width: 100%;
    height: 80%;
  }
  p {
    font-size: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 5px 0px;
    b {
      font-size: 13px;
      font-weight: 700;
      color: red;
    }
  }
}
.mobile_container2 {
  width: 24%;
  height: 99%;
  background-color: #fff;
  margin: 0 5px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
.mobile_container2:hover {
  transform: scale(1.05);
  transition: all 1s;
  background-color: #fff;
}
</style>